package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.PubCenter;
import com.hs.service.PubCenterService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("pubcenter")
public class PubCenterController {
    @Autowired
    private PubCenterService pubCenterService;
    @PostMapping
    public R addpubCenter(@RequestBody PubCenter pubCenter) {
        Integer i = pubCenterService.addPubCenter(pubCenter);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @DeleteMapping("{id}")
    public R delpubCenter(@PathVariable("id") Integer id) {
        Integer i = pubCenterService.deletePubCenter(id);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @PutMapping
    public R updatepubCenter(@RequestBody PubCenter pubCenter) {
        Integer i = pubCenterService.updatePubCenter(pubCenter);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @GetMapping("{id}")
    public R getpubCenterById(@PathVariable("id") Integer id) {
        PubCenter pubCenter = pubCenterService.getPubCenterById(id);
        return R.ok(pubCenter);
    }
    @GetMapping("page")
    public R getpubCenterByPage(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                @RequestParam(defaultValue = "2",required = false)Integer pageSize) {
        PageInfo<PubCenter> pubCenterPage = pubCenterService.getPubCenterPage(pageNum, pageSize);
        return R.ok(pubCenterPage);
    }
}
